#include <bits/stdc++.h>
using namespace std;
#define int long long

int n, m, L[3005][3005], R[3005][3005], U[3005][3005], D[3005][3005], sum[5005][5005];
char s[3004][3004];

signed main() {
	freopen("star.in", "r", stdin); freopen("star.out", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		cin >> (s[i] + 1);
		for (int j = 1; j <= m; ++j) {
			if (s[i][j] == s[i - 1][j]) U[i][j] = U[i - 1][j] + 1;
			if (s[i][j] == s[i][j - 1]) L[i][j] = L[i][j - 1] + 1;
			sum[i - U[i][j]][j - L[i][j]]++;
		}
	}
	for (int i = n ; i >= 1; --i) {
		for (int j = m; j >= 1; --j) {
			if (s[i][j] == s[i + 1][j]) D[i][j] = D[i + 1][j] + 1;
			if (s[i][j] == s[i][j + 1]) R[i][j] = R[i][j + 1] + 1;
		}
	}
	int ans = 0;
	for (int a = 1; a <= n; ++a) {
		for (int b = 1; b <= m; ++b) {
			for (int x = a + 1; x <= a + D[a][b] ; ++x) {
				for (int y = b + 1; y <= b + R[a][b]; ++y) {
					if(x <= a + U[x][y] && y <= b + L[x][y]) ++ans;
				}
			}
		}
	}
	cout << ans << "\n";
}
